﻿package Framework.MQ
{
    import Framework.Serialize.*;

    public class MessageBlock extends Object
    {
        private var _messageHead:MessageHead;
        private var _messageBase:IMessageBase;

        public function MessageBlock()
        {
            this._messageHead = new MessageHead();
            return;
        }// end function

        public function __write(param1:SerializeStream) : void
        {
            this.__writeHead(param1);
            this.__writeBody(param1);
            return;
        }// end function

        public function __writeHead(param1:SerializeStream) : void
        {
            this._messageHead.__write(param1);
            return;
        }// end function

        public function __writeBody(param1:SerializeStream) : void
        {
            if (this._messageBase)
            {
                param1.writeSize(this._messageBase.getType());
                this._messageBase.__write(param1);
                if (this._messageBase.msgEx)
                {
                    param1.writeByte(1);
                    this._messageBase.msgEx.__write(param1);
                }
                else
                {
                    param1.writeByte(0);
                }
            }
            else
            {
                param1.writeSize(0);
            }
            return;
        }// end function

        public function __read(param1:SerializeStream) : void
        {
            this.__readHead(param1);
            this.__readBody(param1);
            return;
        }// end function

        public function __readHead(param1:SerializeStream) : void
        {
            this._messageHead.__read(param1);
            return;
        }// end function

        public function __readBody(param1:SerializeStream) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = param1.readSize();
            if (_loc_2 != 0)
            {
                this._messageBase = MessageManager.instance().createMessage(_loc_2);
                this._messageBase.__read(param1);
                _loc_3 = param1.readByte();
                if (_loc_3 != 0)
                {
                    this._messageBase.msgEx = new IMessageEx();
                    this._messageBase.msgEx.__read(param1);
                }
            }
            return;
        }// end function

        public function get messageHead() : MessageHead
        {
            return this._messageHead;
        }// end function

        public function set messageHead(param1:MessageHead) : void
        {
            this._messageHead = param1;
            return;
        }// end function

        public function get messageBase() : IMessageBase
        {
            return this._messageBase;
        }// end function

        public function set messageBase(param1:IMessageBase) : void
        {
            this._messageBase = param1;
            return;
        }// end function

    }
}
